##Replication code for Caddel, Jeremy (2013) "Domestic Competition over Trade Barriers in the US International Trade Commision" International Studies Quarterly.

library(lmtest)

##Load Data

data<-read.csv(   file="~Caddel_ITC_Dataset.csv", header=T, stringsAsFactors=FALSE, sep=",")

##Ensure .csv data reads as numeric

data$ChangeImports<-as.numeric(data$ChangeImports)
data$DumpingMargin<-as.numeric(data$DumpingMargin)

##Convert House and Senate Support to binary: 1 = at least one active support/oppose, 0 =else

data$SenateSupportAuth<-ifelse(data$SenateSupportAuth>0,1,0)
data$SenateOpposeAuth<-ifelse(data$SenateOpposeAuth>0,1,0)
data$HouseSupportAuth<-ifelse(data$HouseSupportAuth>0,1,0)
data$HouseOpposeAuth<-ifelse(data$HouseOpposeAuth>0,1,0)

##Ensure that industry code reads as factor not numeric

data$NAICS<-as.factor(data$NAICS)

##Omit cases with missing data. 

data<-na.omit(data)

##NB: See footnote 6 of the paper. The original draft did not include case-specific variables (for Change in Production, Domestic Market Share, Dumping Margin) as this data is redacted in several cases. These variables were included at the suggestion of a reviewer, because they do provide a more effective control for the legal issues considered by the ITC. The trade off is that the dataset is reduced from 378 to 221 cases, but the substantive findings do not change. I include the entire original dataset so that others may build upon it and further explore the data. To run the models over the entire dataset, simply omit ChangeProduction, DomMarketShare, and ChangeImport from the control variables.


##Null Model

mnull<-glm(Outcome ~ 1, family=binomial(link="logit"), data)
summary(mnull)

##Model 0: includes only case factors (controls)

m0<-glm(Outcome ~ Type + Unemployment + TradeDeficit + CapUtil + ChangeProduction + DomMarketShare + ChangeImports + DumpingMargin, family=binomial(link="logit"), data)
summary(m0)

##log Likelihood
lrtest(mnull, m0)

## pseudo R^2
lr.stat <- lrtest(modn, case)
n<-220
(1-exp((case$dev-case$null)/n))/(1-exp(-case$null/n))


##Model 1: includes case factors (controls), industry size and concentration, and representation on oversight committees

m1<-glm(Outcome ~ Type + Unemployment + TradeDeficit + CapUtil + IndustryEmploy + HerfIndex + ChangeProduction + DomMarketShare + ChangeImports + DumpingMargin + HouseAuth + SenateAuth, family=binomial(link="logit"), data)
summary(m1)

##log Likelihood
lrtest(mnull, m1)

## pseudo R^2
(1-exp((m1$dev-m1$null)/n))/(1-exp(-m1$null/n))

##Model 2: includes case factors (controls), measure of industry support/opposition, and measure of active oversight support/opposition

m2<-glm(Outcome ~ Type + Unemployment + TradeDeficit + CapUtil + ChangeProduction + DomMarketShare + ChangeImports + DumpingMargin + HouseSupportAuth + SenateSupportAuth + HouseOpposeAuth + SenateOpposeAuth  + Industry.Split + MNC + Downstream, family=binomial(link="logit"), data)
summary(m2)

##log Likelihood
lrtest(mnull, m2)

## pseudo R^2
(1-exp((m2$dev-m2$null)/n))/(1-exp(-m2$null/n))


##Model 3: includes all variables
m3<-glm(Outcome ~ Type + Unemployment + TradeDeficit + CapUtil + IndustryEmploy + HerfIndex + ChangeProduction + DomMarketShare + ChangeImports + DumpingMargin + HouseAuth + SenateAuth + HouseSupportAuth + SenateSupportAuth + HouseOpposeAuth + SenateOpposeAuth + Industry.Split + MNC + Downstream, family=binomial(link="logit"), data)
summary(m3)

##log Likelihood
lrtest(mnull, m3)

## pseudo R^2
(1-exp((m3$dev-m3$null)/n))/(1-exp(-m3$null/n))

